//
// GPSMapEdit
// (c) Konstantin Galichsky (kg@infratel.com), 2002-2004
//
// Edit control helpers.
//

# include "StdAfx.h"
# include "EditHelpers.h"
# include "ParseHelpers.h"

bool ValidateAsFloat (HWND _hCtl) {
	const size_t cLen = ::GetWindowTextLength (_hCtl);
	char * const str = reinterpret_cast<char *> (alloca ((cLen + 1)*sizeof (char)));
	::GetWindowText (_hCtl, str, cLen + 1);

	float f;
	const char * pEnd = NULL;
	return ParseReal (str, str + cLen, & pEnd, f) && pEnd == str + cLen;
}

float GetTextAsFloat (HWND _hCtl) {
	const size_t cLen = ::GetWindowTextLength (_hCtl);
	char * const str = reinterpret_cast<char *> (alloca ((cLen + 1)*sizeof (char)));
	::GetWindowText (_hCtl, str, cLen + 1);

	return ParseReal (str);
}

/////////////////////////////////////////

bool ValidateAsArc (HWND _hCtl) {
	const size_t cLen = ::GetWindowTextLength (_hCtl);
	char * const str = reinterpret_cast<char *> (alloca ((cLen + 1)*sizeof (char)));
	::GetWindowText (_hCtl, str, cLen + 1);

	float f;
	const char * pEnd = NULL;
	return ParseArc (str, str + cLen, & pEnd, f) && pEnd == str + cLen;
}

float GetTextAsArc (HWND _hCtl) {
	const size_t cLen = ::GetWindowTextLength (_hCtl);
	char * const str = reinterpret_cast<char *> (alloca ((cLen + 1)*sizeof (char)));
	::GetWindowText (_hCtl, str, cLen + 1);

	return ParseArc (str);
}
